//
//  SNOrderFormDetailGoodsModel.m
//  app
//
//  Created by 王少宁 on 15/5/18.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "SNOrderFormDetailGoodsModel.h"

@implementation SNOrderFormDetailGoodsModel

- (instancetype)initWithDict:(NSDictionary *)dict commentBtn:(BOOL)commmentBtn returnGoodsBtnType:(ReturnGoodsBtnType)type
{
    if (self = [super init]) {
        _act_id = [dict[@"act_id"] stringValue];
        _shop_id = dict[@"shop_id"] ?  [dict[@"shop_id"] stringValue] : @"0";
        _product_id = [dict[@"product_id"] stringValue];
        DLog(@"%@",dict[@"shop_id"]);
        _title_pic = dict[@"title_pic"];
        _product_title = dict[@"product_title"];
        _price = [NSString stringWithFormat:@"%.2f",[dict[@"price"] floatValue]];
        _sale_price = [dict[@"sale_price"] stringValue];
        _product_num = [dict[@"product_num"] stringValue];
        
        _comments = [dict[@"comments"] stringValue];
        _returns = [dict[@"returns"] stringValue];
        
        _includeCommentBtn = commmentBtn;
        _returnGoodsBtnType = type;
        
//        if (commmentBtn || type!=ReturnGoodsNone) {
//            _cellHeight = 126;
//        } else {
//            _cellHeight = 86;
//        }
        
        //判断有无赠品
        BOOL gift = NO;
        id giftJson = dict[@"gift"];
        
        if ([giftJson isKindOfClass:[NSDictionary class]]) {
            NSDictionary * giftDict = (NSDictionary *)giftJson;
            if (giftDict.allKeys.count > 0) {
                gift = YES;
            } else {
                gift = NO;
            }
        }
        
        if (gift) {
            _giftModel = [SNGiftModel modelWithDict:(NSDictionary *)giftJson];
        }
        
        
#warning - 促销活动的测试数据，接口确定下来之后以下代码需要改正
//                NSDictionary * promotionDic = @{@"id":@5,
//                                                @"name":@"测试包邮",
//                                                @"title":@"全场,满99包邮"
//                                                };
//                _promotionModel = [SNPromotionModel modelWithDict:promotionDic];
        
        if (_giftModel.gift && _promotionModel.promotion) {
            _cellHeight = kGoodsViewHeight + kGiftViewHeight * 2;
        } else if (_giftModel.gift || _promotionModel.promotion) {
            _cellHeight = kGoodsViewHeight + kGiftViewHeight;
        } else {
            _cellHeight = kGoodsViewHeight;
        }
        
    }
    return self;
}

+ (instancetype)modelWithDict:(NSDictionary *)dict commentBtn:(BOOL)commmentBtn returnGoodsBtnType:(ReturnGoodsBtnType)type
{
    return [[self alloc] initWithDict:dict commentBtn:commmentBtn returnGoodsBtnType:type];
}

@end
